{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "99a80181",
   "metadata": {},
   "source": [
    "# ⚠️ PLANNER NOT YET IMPLEMENTED IN PYTHON\n",
    "\n",
    "# Introduction to the Planner\n",
    "\n",
    "The Planner is one of the fundamental concepts of the Semantic Kernel. It makes use of the collection of skills that have been registered to the kernel and using AI, will formulate a plan to execute a given ask.\n",
    "\n",
    "Read more about it [here](https://aka.ms/sk/concepts/planner)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "04e5cf15",
   "metadata": {},
   "outputs": [],
   "source": [
    "!python -m pip install -r requirements.txt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "11e59885",
   "metadata": {},
   "outputs": [],
   "source": [
    "import semantic_kernel as sk\n",
    "from semantic_kernel.ai.open_ai import AzureTextCompletion, OpenAITextCompletion\n",
    "\n",
    "kernel = sk.Kernel()\n",
    "\n",
    "useAzureOpenAI = False\n",
    "\n",
    "# Configure AI backend used by the kernel\n",
    "if useAzureOpenAI:\n",
    "    deployment, api_key, endpoint = sk.azure_openai_settings_from_dot_env()\n",
    "    kernel.config.add_text_backend(\"dv\", AzureTextCompletion(deployment, endpoint, api_key))\n",
    "else:\n",
    "    api_key, org_id = sk.openai_settings_from_dot_env()\n",
    "    kernel.config.add_text_backend(\"dv\", OpenAITextCompletion(\"text-davinci-003\", api_key, org_id))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9c885ced",
   "metadata": {},
   "source": [
    "### Setting Up the Planner\n",
    "The planner is located in the Semantic Kernel's CoreSkills and requires Orchestration"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "948d50fa",
   "metadata": {},
   "outputs": [],
   "source": [
    "# TODO: implement in Python"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "147587de",
   "metadata": {},
   "source": [
    "You can see that the Planner took my ask and converted it into an XML-based plan detailing\n",
    "how the AI would go about solving this task, making use of the skills that the Kernel has available to it."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a5d86739",
   "metadata": {},
   "source": [
    "### Providing skills to the planner\n",
    "The planner needs to know what skills are available to it. Here we'll give it access to the `SummarizeSkill` and `WriterSkill` we have defined on disk."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ca0e7604",
   "metadata": {},
   "outputs": [],
   "source": [
    "# TODO: implement in Python"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "deff5675",
   "metadata": {},
   "source": [
    "Define your ASK. What do you want the Kernel to do?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0d537981",
   "metadata": {},
   "outputs": [],
   "source": [
    "# TODO: implement in Python"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1318dc72",
   "metadata": {},
   "source": [
    "As you can see in the above plan, the AI has determined which functions to call \n",
    "in order to fulfill the user ask. The output of each step of the plan gets set as `setContextVariable` which makes it available as `input` to the next skill. "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a64c88a7",
   "metadata": {},
   "source": [
    "Let's also define an inline skill and have it be available to the Planner.\n",
    "Be sure to give it a function name and skill name."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e973007f",
   "metadata": {},
   "outputs": [],
   "source": [
    "# TODO: implement in Python"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "305743f5",
   "metadata": {},
   "source": [
    "Let's update our ask using this new skill."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bfd23ac4",
   "metadata": {},
   "outputs": [],
   "source": [
    "# TODO: implement in Python"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f5e6ac56",
   "metadata": {},
   "source": [
    "### Executing the plan\n",
    "\n",
    "Now that we have a plan, let's try to execute it! The Planner has a skill called `ExecutePlan`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cf30b5da",
   "metadata": {},
   "outputs": [],
   "source": [
    "# TODO: implement in Python"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
